/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package questionbook.model;

import java.util.Date;
import java.util.List;
import org.openrdf.model.Literal;
import org.openrdf.model.URI;


/**
 * Represents an User in the System
 * 
 * @author stefanstift
 */
public class Person extends StandardModel {

    /**
     * The Firstname of the User
     */
    private String firstName;

    /**
     *  The Lastname of the User
     */
    private String lastName;

    /**
     * The mail address of the User - if no external Identifier
     * is specified, this is the identifier for the User
     */
    private String mbox;

    /**
     * The password of the User, ecrypted with Md5
     */
    private String md5Password;

    /**
     * The Class fo the User (e.g. ExpertUser, TrustUser,...)
     */
    private UserClass userClass;

    /**
     *  The Date of the Registration or the Sync-Insert
     */
    private Date createdAt;

    /**
     * The external Identifier with Type String
     */
    private String extStringId;

    /**
     * The external Identifier with Type Long
     */
    private long   extLongId = 0;


    /**
     * A transient Field to store the second password attempt during login
     */
    private String tempPassword;

    /**
     * a List of all Users that a Freinds with this User
     */
    private List<Person> friendList;


    /**
     * Creates a new Person instance with the specified URI
     *
     * @param uri
     */
    public Person(URI uri) {
        super(uri);
    }

    /**
     * Creates a new Person instance with the specified URI-String
     *
     * @param uri
     */
    public Person(String uri) {
        super(uri);
    }

    /**
     *
     * @return the Firstname of the User
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     *
     * @return the Firstname of the User as a Literal
     */
    public Literal getFirstNameLiteral() {
        return this.getStringLiteral(firstName);
    }

    /**
     * Sets the Firstname of the User
     *
     * @param firstName
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     *
     * @return the Lastname of the User as a Literal
     */
    public Literal getLastNameLiteral() {
        return this.getStringLiteral(lastName);
    }

    /**
     *
     * @return the Firstname of the User
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the Lastname of the User
     *
     * @param lastName
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     *
     * @return the Mail-Address of the User as a Literal
     */
    public Literal getMboxLiteral() {
        return this.getStringLiteral(mbox);
    }

    /**
     *
     * @return the Mail-Address of the User
     */
    public String getMbox() {
        return mbox;
    }

    /**
     * Sets the Mail-Address of the User
     *
     * @param mbox
     */
    public void setMbox(String mbox) {
        this.mbox = mbox;
    }

    /**
     *
     * @return a List of all Users that are friends with this User
     */
    public List<Person> getFriendList() {
        return friendList;
    }

    /**
     * Set a List of all Friends for this User
     *
     * @param friendList
     */
    public void setFriendList(List<Person> friendList) {
        this.friendList = friendList;
    }

    /**
     *
     * @return the Md5 Hash of the Users Password as a Literal
     */
    public Literal getMd5PasswordLiteral() {
        return this.getStringLiteral(md5Password);
    }

    /**
     *
     * @return the Md5 Hash of the Users Password
     */
    public String getMd5Password() {
        return md5Password;
    }

    /**
     * Sets the Md5 Hash of the Users Password
     *
     * @param md5Password
     */
    public void setMd5Password(String md5Password) {
        this.md5Password = md5Password;
    }

    /**
     *
     * @return the temporary Password for the login
     */
    public String getTempPassword() {
        return tempPassword;
    }

    /**
     * Sets the temporary Password for the login
     *
     * @param tempPassword
     */
    public void setTempPassword(String tempPassword) {
        this.tempPassword = tempPassword;
    }

    /**
     *
     * @return the assigned UserClass for the User, if there is none - the User is a
     * StandardUser
     */
    public UserClass getUserClass() {

        if(this.userClass == null)
            this.userClass = UserClass.StdUser;

        return userClass;
    }

    /**
     * Sets the UserClass of the User
     *
     * @param userClass
     */
    public void setUserClass(UserClass userClass) {
        this.userClass = userClass;
    }

    /**
     *
     * @return the Concatenation of the Users Firstname and Lastname
     */
    public String getName()
    {
        return this.firstName + " " + this.lastName;
    }

    /**
     *
     * @return the external Long Identifier as a Literal
     */
    public Literal getExtLongIdLiteral() {
        return this.getLongLiteral(this.extLongId);
    }

    /**
     *
     * @return the external Long Identifier
     */
    public long getExtLongId() {
        return extLongId;
    }

    /**
     * Sets the external Long Identifier from String-Representation
     *
     * @param extLongId
     */
    public void setExtLongId(String extLongId) {
        this.extLongId = Long.parseLong(extLongId);
    }

    /**
     * Sets the external Long Identifier 
     *
     * @param extLongId
     */
    public void setExtLongId(long extLongId) {
        this.extLongId = extLongId;
    }

    /**
     * 
     * @return the external String Identifier as a Literal
     */
    public Literal getExtStringIdLiteral() {
        return this.getStringLiteral(this.extStringId);
    }

    /**
     *
     * @return the external Long Identifier
     */
    public String getExtStringId() {
        return extStringId;
    }

    /**
     *  Sets the external Long Identifier 
     *
     * @param extStringId
     */
    public void setExtStringId(String extStringId) {
        this.extStringId = extStringId;
    }

    /**
     *
     * @return  Timestamp of Create-Date as Long-Literal
     */
    public Literal getCreatedAtLiteral() {
        return this.getLongLiteral(this.createdAt.getTime());
    }

    /**
     *
     * @return Date-Object of the Create-Date
     */
    public Date getCreatedAt() {
        return createdAt;
    }

    /**
     *
     * @return String-Representation of the Create-Date
     */
    public String getCreatedAtString() {
        return this.format.format(createdAt);
    }

    /**
     * Sets the Create-Date with a Timestamp-String
     *
     * @param timestamp
     */
    public void setCreatedAt(String timestamp) {
        this.createdAt = new Date(Long.parseLong(timestamp));
    }

    /**
     * Sets the Create-Date with a Date-Object
     *
     * @param createdAt
     */
    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }



    


}
